package me.zixing.java.chapter04.task02.entity;

import java.util.Objects;

/**
 * Created by bingh on 2017/10/12.
 */
public class Student implements Comparable<Student>{
    private int studentId;
    private String studentName;
    private float chineseScore;
    private float mathScore;
    private float englishScore;

    public Student() {
    }

    public Student(int studentId, String studentName, float chineseScore, float mathScore, float englishScore) {
        this.studentId = studentId;
        this.studentName = studentName;
        this.chineseScore = chineseScore;
        this.mathScore = mathScore;
        this.englishScore = englishScore;
    }

    public int getStudentId() {
        return studentId;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public float getChineseScore() {
        return chineseScore;
    }

    public void setChineseScore(float chineseScore) {
        this.chineseScore = chineseScore;
    }

    public float getMathScore() {
        return mathScore;
    }

    public void setMathScore(float mathScore) {
        this.mathScore = mathScore;
    }

    public float getEnglishScore() {
        return englishScore;
    }

    public void setEnglishScore(float englishScore) {
        this.englishScore = englishScore;
    }


    @Override
    public int compareTo(Student o) {
        return o.studentId >= this.studentId ? 1 : -1;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return studentId == student.studentId &&
                Float.compare(student.chineseScore, chineseScore) == 0 &&
                Float.compare(student.mathScore, mathScore) == 0 &&
                Float.compare(student.englishScore, englishScore) == 0 &&
                Objects.equals(studentName, student.studentName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(studentId, studentName, chineseScore, mathScore, englishScore);
    }

    @Override
    public String toString() {
        String studentFormat = String.format("学号:%d\t姓名:%s\t\t总分:%.2f\t语文成绩:%.2f\t\t数学成绩:%.2f\t\t英语成绩:%.2f\t\t",
                studentId,studentName,chineseScore+mathScore+englishScore,chineseScore,mathScore,englishScore);
        return studentFormat;
    }
}
